import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MenuQuery, MenuVO, MenuForm, MenuDelete, MenuMove } from "./types";
const APPTYPE = import.meta.env.VITE_APP_TYPE;
/**
 * 获取路由列表
 */
export function listRoutes(type: string) {
  return request({
    // url: "/system/loginUserPower/tree?applicationType=system",
    url: `/system/loginUserPower/tree?applicationType=${APPTYPE}&parentMenuId=${type}`,
    method: "post",
    // data: usePost({}),
    // data: {},
  });
}

/**
 * 获取菜单树形列表
 *
 * @param queryParams
 */
export function listMenus(queryParams: MenuQuery): AxiosPromise<MenuVO[]> {
  return request({
    url: "/system/sysPermission/roleTree",
    method: "post",
    data: queryParams,
  });
}
export function listMenusManager(): AxiosPromise<MenuVO[]> {
  return request({
    url: "/system/sysPermission/manage",
    method: "post",
  });
}

/**
 * 获取菜单下拉树形列表
 */
export function getMenuOptions(): AxiosPromise<OptionType[]> {
  return request({
    url: "/api/v1/menus/options",
    method: "get",
  });
}

/**
 * 获取菜单表单数据
 *
 * @param id
 */
export function getMenuForm(id: number): AxiosPromise<MenuForm> {
  return request({
    url: "/api/v1/menus/" + id + "/form",
    method: "get",
  });
}

/**
 * 添加菜单
 *
 * @param data
 */
export function addMenu(data: any) {
  return request({
    url: "/system/sysPermission/save",
    method: "post",
    data: data,
  });
}

/**
 * 修改菜单
 *
 * @param id
 * @param data
 */
export function updateMenu(id: string, data: MenuForm) {
  return request({
    url: "/api/v1/menus/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除菜单
 *
 * @param id 菜单ID
 */
export function deleteMenu(data: MenuDelete) {
  return request({
    url: "system/sysPermission/delete",
    method: "post",
    data: data,
  });
}

/**
 * 移动菜单
 *
 * @param id 菜单ID
 */
export function moveMenu(data: MenuMove) {
  return request({
    url: "system/sysPermission/move",
    method: "post",
    data: data,
  });
}
